package com.strange.mdl.module.mdl.controller.app.dailydharma;

import com.strange.mdl.framework.apilog.core.annotation.ApiAccessLog;
import com.strange.mdl.framework.common.pojo.CommonResult;
import com.strange.mdl.framework.common.pojo.PageParam;
import com.strange.mdl.framework.common.pojo.PageResult;
import com.strange.mdl.framework.common.util.object.BeanUtils;
import com.strange.mdl.framework.excel.core.util.ExcelUtils;
import com.strange.mdl.module.mdl.controller.admin.dailydharma.vo.DailydharmaPageReqVO;
import com.strange.mdl.module.mdl.controller.admin.dailydharma.vo.DailydharmaRespVO;
import com.strange.mdl.module.mdl.controller.admin.dailydharma.vo.DailydharmaSaveReqVO;
import com.strange.mdl.module.mdl.dal.dataobject.dailydharma.DailydharmaDO;
import com.strange.mdl.module.mdl.dal.dataobject.dailydharma.DailydharmaUsersDO;
import com.strange.mdl.module.mdl.dal.dataobject.debatehall.DebatehallDO;
import com.strange.mdl.module.mdl.service.dailydharma.DailydharmaService;
import com.strange.mdl.module.mdl.utils.ConvertUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import static com.strange.mdl.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static com.strange.mdl.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 今日弘法")
@RestController
@RequestMapping("/mdl/appdailydharma")
@Validated
public class AppDailydharmaController {

    @Resource
    private DailydharmaService dailydharmaService;


    @GetMapping("/get")
    @Operation(summary = "获得今日弘法")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @Parameter(name = "userId", description = "用户id", required = false, example = "1024")
    @PermitAll
    public CommonResult<DailydharmaRespVO> getDailydharma(@RequestParam("id") Long id, @RequestParam(value = "userId", required = false) Long userId) {
        DailydharmaDO dailydharma = dailydharmaService.getDailydharma(id, userId);
        DailydharmaRespVO bean = BeanUtils.toBean(dailydharma, DailydharmaRespVO.class);
        return success(bean);
    }

    @GetMapping("/page")
    @Operation(summary = "获得今日弘法分页")
    @PermitAll
    public CommonResult<PageResult<DailydharmaRespVO>> getDailydharmaPage(@Valid DailydharmaPageReqVO pageReqVO) {
        PageResult<DailydharmaDO> pageResult = dailydharmaService.getDailydharmaPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DailydharmaRespVO.class));
    }

    @GetMapping("/recommendation")
    @Operation(summary = "相关推荐")
    @PermitAll
    public CommonResult<PageResult<DailydharmaRespVO>> recommendation(@Valid DailydharmaPageReqVO pageReqVO) {
        PageResult<DailydharmaDO> pageResult = dailydharmaService.getDailydharmaPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DailydharmaRespVO.class));
    }

    @GetMapping("/operate")
    @Operation(summary = "操作状态")
    @Parameter(name = "userId", description = "用户编号", required = true, example = "123456")
    @Parameter(name = "id", description = "弘法id", required = true, example = "789012")
    @Parameter(name = "type", description = "支持类型", required = true, example = "1")
    @PermitAll
    public CommonResult<DailydharmaDO> operate(
            @RequestParam("userId") Long userId,
            @RequestParam("id") Long id,
            @RequestParam("tag") String tag,
            @RequestParam("status") Integer status) {
        DailydharmaDO operate = dailydharmaService.operate(userId, id, tag, status);
        return success(operate);
    }
}